<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\MembershipCode;
use Carbon\Carbon;

class MembershipCodeSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // 生成测试兑换码
        $codes = [
            // 日卡兑换码
            ['type' => 'day', 'count' => 5],
            // 月卡兑换码
            ['type' => 'month', 'count' => 3],
            // 年卡兑换码
            ['type' => 'year', 'count' => 2],
            // 永久卡兑换码
            ['type' => 'permanent', 'count' => 1],
        ];

        foreach ($codes as $codeType) {
            for ($i = 0; $i < $codeType['count']; $i++) {
                MembershipCode::generateCode(
                    $codeType['type'],
                    Carbon::now()->addMonths(6) // 兑换码6个月后过期
                );
            }
        }

        // 生成一些特定的测试兑换码（方便测试）
        $testCodes = [
            ['code' => 'TEST1DAY12345678', 'type' => 'day'],
            ['code' => 'TESTMONTH1234567', 'type' => 'month'],
            ['code' => 'TESTYEAR12345678', 'type' => 'year'],
            ['code' => 'TESTPERM12345678', 'type' => 'permanent'],
        ];

        foreach ($testCodes as $testCode) {
            $duration = MembershipCode::$membershipTypes[$testCode['type']]['duration'];

            MembershipCode::create([
                'code' => $testCode['code'],
                'type' => $testCode['type'],
                'duration' => $duration,
                'expires_at' => Carbon::now()->addMonths(6),
            ]);
        }

//        $this->command->info('Generated membership codes:');
//        $this->command->info('Day cards: TEST1DAY12345678');
//        $this->command->info('Month cards: TESTMONTH1234567');
//        $this->command->info('Year cards: TESTYEAR12345678');
//        $this->command->info('Permanent cards: TESTPERM12345678');
    }
}
